package com.itheima.demo1;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMapDemo1 {
    public static void main(String[] args) {
        //创建HashMap学生对象
        HashMap<Student,String> hm = new HashMap<>();

        //创建三个学生对象
        Student s1 = new Student("zhangsan",24);
        Student s2 = new Student("lisi",25);
        Student s3 = new Student("wangwu",23);
        Student s4 = new Student("wangwu",23);

        //添加元素
        hm.put(s1,"jiangsu");
        hm.put(s2,"zhejiang");
        hm.put(s3,"hujian");
        hm.put(s4,"shandong");

        //遍历集合
        Set<Map.Entry<Student, String>> entries = hm.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+" = "+ value);
        }

        System.out.println("-----------------");
        hm.forEach((student, s) -> System.out.println(student + s));
    }




}
